package com.drondea.testclient.service.provider;

import com.drondea.sms.channel.ChannelSession;
import com.drondea.sms.common.SequenceNumber;
import com.drondea.sms.common.util.CommonUtil;
import com.drondea.sms.common.util.SgipSequenceNumber;
import com.drondea.sms.message.IMessage;
import com.drondea.sms.message.sgip12.SgipSubmitRequestMessage;
import com.drondea.testclient.util.counter.SgipAtomicUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author shd
 * @date 2022/7/14 10:00
 */

@Slf4j
public class SgipClientMessageProvider extends AbstractClientMessageProvider {
    
    @Override
    public List<IMessage> getTcpMessages(ChannelSession channelSession) {
        SgipSubmitRequestMessage requestMessage = (SgipSubmitRequestMessage) MESSAGES_QUEUE.poll();
        if (requestMessage == null) {
            return null;
        }
        SequenceNumber sequenceNumber = channelSession.getSequenceNumber();
        SgipSequenceNumber sgipSequenceNumber = new SgipSequenceNumber(3027130067L, sequenceNumber.next());
        requestMessage.getHeader().setSequenceNumber(sgipSequenceNumber);

        //切分长短信
        List<IMessage> longMsgSlices = CommonUtil.getLongMsgSlices(requestMessage, channelSession.getConfiguration(), sequenceNumber);
        SgipAtomicUtil.SEND_COUNT.addAndGet(longMsgSlices.size());
        return longMsgSlices;
    }

}
